<?php
/**
 * @author 	 	 faithsmine@gmail.com
 * @copyright            www
 * @version              1.0
 * @name 		 login.php
 * @todo 		 用户 登录/ 退出
 * @final 		 2009-12-11
 */
define('IN_YCTOOL', true);//定义该文件合法性
require_once('config.php');
require_once(DIR_COMM . 'common.php');
$emvalue	= isset($_POST['emvalue']) ? $_POST['emvalue'] : '';
$action		= isset($_GET['action']) ? $_GET['action'] : '';
$userpass	= isset($_POST['userpass']) ? $_POST['userpass'] : '';
$cookie		= isset($_POST['cookie']) ? $_POST['cookie'] : 0;
$url = $_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] :'./admin/';
substr( basename($url) , 0 , 9) == 'login.php' && $url = './admin/';
 
$nobarfooter = 1;
if ($action == 'logout')
{
    $user->logout();

    func::obHeader('./');
    exit();
}

if ($user->userinfo['userid'] > 0)
{
    func::obHeader($url);
    exit();
}
if ($emvalue && $userpass)
{
    $ret = $user->Login($emvalue, $userpass, $cookie);
    switch ($ret)
    {
	case "USER_LOGIN_SUCCESS":
	    $user->updateLogin($user->userinfo['userid']);

	    $modifytime = db::getOne(DB_TABLEPRE . 'user_basic', 'loginone', 'userid = ' . $user->userinfo['userid']);
	  echo $modifytime;  
	    if(!$modifytime)
	    {
		$upuser['loginone'] = 1;
		//更新用户信息数据库
		$user->updateU($user->userinfo['userid'], $upuser);
		func::obHeader($url . 'admin/');
	       	exit;
            }	    
	    func::obHeader($url);
	    break;
	case "USER_ACTIVE_FAIL":
	    $rs = $user->getUserInfo($emvalue);
	    $email = $rs['email'];
	    $userid = $rs['userid'];
	    if($email)
	    {
		/*
		require_once(DIR_COMM . 'sendmail.php');
		$posttext = '
<HTML><HEAD>
<TITLE>Mail</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset='.Email_CHARSET.'">
</HEAD>
<BODY bgColor=#FFFFFF topmargin=5
leftmargin=5 style="FONT-SIZE:9pt; FONT-FAMILY:宋体">
<div>'.$language['sns_hellow'].$username.'：<br>
<br>
'.$language['sns_justnowreg'].YCTOOL_HTTPHOST.$language['sns_finishreg'].' <br>
<a href="http://'.YCTOOL_HTTPHOST.'/c.php?code='.$findpsw.'&email='.$email.'"
>http://'.YCTOOL_HTTPHOST.'/c.php?code='.$findpsw.'&email='.$email.'</a><br>
<br>
'.$language['sns_joinlinkone'].YCTOOL_HTTPHOST.$language['sns_joinlinktwo'].'
<br>
<br>
<br>
<a href="http://'.YCTOOL_HTTPHOST.'">'.YCTOOL_HTTPHOST.'</a>'.$language['sns_joinlinktwo'].'<br>
<br>
<br>
</div>
</BODY></HTML>';
$mailok = SendMail($email, YCTOOL_HTTPHOST.$language['sns_confirmreg'], $posttext, 'noreply@'.YCTOOL_HTTPHOST, YCTOOL_HTTPHOST, true, CHARSET);
		 */
		func::showMsg("您的帐户还没有激活,需要找管理员激活您的帐户。<br /> <br /> ", './');
		}
	    break;
	case "USER_PASSWORD_ERROR":
	    func::alertMsg("密码错误", './');
	    break;
	case "USER_NOT_EXIST":
	    func::alertMsg("用户名不存在", './');
	    break;
	default:;
    }
    exit();
}

require_once DIR_COMM.'template.func.php';
require_once tpl('login.html', $tpldir);
?>
